/**
 * https://leetcode.cn/problems/minimum-size-subarray-sum/submissions/560559000/
 * 209. 长度最小的子数组
 * medium, 李佳颖 2024.9.2
 * 滑动窗口
 */

class Solution {
public:
    int minSubArrayLen(int target, vector<int>& nums) {
        int i=0,j=0;
        int sum=0;
        int qu=0;
        while (j<nums.size()) {
            sum+=nums[j];
            ++j;
            while(sum>=target) {
                if (qu==0)
                    qu=j;
                else
                    qu=min(qu,j-i);
                sum-=nums[i];
                i+=1;
            }
        }
        return qu;
    }
};

